function myPromiseRace(promises) {
  return new Promise((resolve, reject) => {
    if (promises.length === 0) return resolve();
    promises.forEach((promise) => {
      Promise.resolve(promise).then(resolve).catch(reject);
    });
  });
}

const promise1 = new Promise((resolve) =>
  setTimeout(resolve, 100, 'Promise 1')
);
const promise2 = new Promise((resolve) =>
  setTimeout(resolve, 200, 'Promise 2')
);
const promise3 = new Promise((resolve, reject) =>
  setTimeout(reject, 150, 'Promise 3')
);

myPromiseRace([promise1, promise2, promise3])
  .then((result) => {
    console.log('Race resolved with:', result);
  })
  .catch((error) => {
    console.log('Race rejected with:', error);
  });
